/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


    size_t EcmaRuntimeInterface::ResolveInlinableNativeMethod(MethodPtr method) const
    {
        if (JsMethodCast(method)->IsNative()) {
            static const std::unordered_map<const void *, EcmaRuntimeCallerId> INLINABLE_BUILTINS {
% Builtins.spaces.each do |space|
%   space.inlinable_methods.each do |method|
                {reinterpret_cast<const void *>(builtins::<%= space.name.snakecase %>::<%= method.gen_cpp_id %>), EcmaRuntimeCallerId::BUILTINS_ID_<%= space.name %>_<%= method.gen_cpp_id %>},
%   end
%   if space.prototype
%       space.prototype.inlinable_methods.each do |method|
                {reinterpret_cast<const void *>(builtins::<%= space.name.snakecase %>::proto::<%= method.gen_cpp_id %>), EcmaRuntimeCallerId::BUILTINS_ID_<%= space.name %>Prototype_<%= method.gen_cpp_id %>},
%       end
%   end
% end
% Builtins.internal_spaces.each do |ispace|
%   ispace.inlinable_methods.each do |method|
                {reinterpret_cast<const void *>(builtins::<%= ispace.name.snakecase %>::<%= method.gen_cpp_id %>), EcmaRuntimeCallerId::BUILTINS_ID_<%= ispace.name %>_<%= method.gen_cpp_id %>},
%   end
%   if ispace.prototype
%       ispace.prototype.inlinable_methods.each do |method|
                {reinterpret_cast<const void *>(builtins::<%= ispace.name.snakecase %>::proto::<%= method.gen_cpp_id %>), EcmaRuntimeCallerId::BUILTINS_ID_<%= ispace.name %>Prototype_<%= method.gen_cpp_id %>},
%       end
%   end
% end
            };
            auto it = INLINABLE_BUILTINS.find(JsMethodCast(method)->GetNativePointer());
            if (it == INLINABLE_BUILTINS.end()) {
                return RUNTIME_CALLER_NUMBER;
            }
            return it->second;
        }

        return RUNTIME_CALLER_NUMBER;
    }
